﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SockLib.Device
{
    /// <summary>
    /// <para >定义设备的注册方法</para>
    /// <para>数据转发方法</para>
    /// <para>数据转换方法(如果有的话)</para>
    /// </summary>
  public  interface IDevice
    {
        /// <summary>
        /// 收到数据是否满足注册条件
        /// </summary>
        /// <param name="Buffer">Socket收到的数据</param>
        /// <param name="DM">如果成功解析，DM写入相应信息</param>
        /// <returns>True：成功解析，False：未能解析（乱数据）</returns>
      bool DeviceReg(byte[] Buffer, ref  DeviceModel DM, out List<DeviceModel.SendMsg> Sendinfo);

      /// <summary>
      /// 中心数据转发规则
      /// </summary>
      /// <param name="ReceiveData">收到的字节数组</param>
      /// <param name="Sendinfo">需要转发的结构体</param>
      /// <returns></returns>
        bool TransferRule(byte[] ReceiveData, out List<DeviceModel.SendMsg> Sendinfo);

        /// <summary>
        /// 节点数据转发规则
        /// </summary>
        /// <param name="ReceiveData">收到的数据</param>
        /// <param name="uid">GPRS的编号</param>
        /// <param name="Sendinfo">需要转发的结构体</param>
        /// <returns></returns>
        bool NodeTransferRule(byte[] ReceiveData, string uid,   ref DeviceModel.SendMsg[] Sendinfo);

       /// <summary>
       /// 心跳包格式
       /// </summary>
       /// <param name="TargetUid">发给的中心模块ID</param>
       /// <param name="uid">在线中心模块ID集合</param>
       /// <returns></returns>
       List< byte[]> HeartBeatConvert(string TargetUid,string[] uid);

       /// <summary>
       /// <para >要发送数据转换：</para>
       /// <para>发送数据转换，有的设备需要转换数据</para>
       /// <para>需要转换的定义转换规则</para>
       /// <para>不需要转换的直接返回数据即可</para>
       /// </summary>
       /// <param name="Data">转换的数据</param>
       /// <returns></returns>
        byte[] SendDataConvert(byte[] Data);

       

       /// <summary>
        /// <para >接收数据转换：</para>
        /// <para>发送数据转换，有的设备需要转换数据</para>
        /// <para>需要转换的定义转换规则</para>
        /// <para>不需要转换的直接返回数据即可</para>
       /// </summary>
        /// <param name="Data">转换的数据</param>
       /// <returns></returns>
        byte[] ReceiveDataConvert(byte[] Data);


      /// <summary>
      /// 心跳包不做任何转发处理
      /// </summary>
      /// <param name="?"></param>
      /// <returns></returns>
       bool IsHeartPack(byte[] Pack);

       /// <summary>
       /// 获取设备名称
       /// </summary>
       /// <returns></returns>
       string DeviceType();


      /// <summary>
      /// 不同设备的不同发送数据打包方式
      /// </summary>
      /// <param name="SendData">要发送的数据</param>
      /// <param name="SendTarget">要发送的目标</param>
      /// <returns></returns>
       byte[] DataPacket(Device.DeviceModel.SendMsg SendMsg);

        /// <summary>
        /// 用于显示在软件信息框中的信息
        /// </summary>
        /// <param name="uid">目标GPRS编号</param>
        /// <param name="msg">要转换的字节数组</param>
        /// <returns></returns>
        string SendString(string uid,byte[] msg);

        /// <summary>
        /// 传进接口的一些配置信息
        /// </summary>
        /// <param name="Params">要传递的参数，用string作为索引</param>
        void SetParars(Dictionary<string ,object> Params);
    }
}
